package leetcode;

import java.util.ArrayList;

public class Solution {
    public static String reverseWords(String s) {
        if(s.length()==0)
            return "";
        String[] a = s.split(" ");
        ArrayList<String> list = new ArrayList<String>();
        for(int i=0;i<a.length;i++){
            if(a[i].length()>0){
                list.add(a[i]);
            }
        }
        String b = "";
        if(list.size()>0){
            for(int i=list.size()-1;i>0;i--){
                b=b+list.get(i)+" ";
            }
            b+=list.get(0);
            return b;
        }
        else
            return "";
    }
    public static void main(String[] args){
        System.out.println(reverseWords(""));
    }
}